require 'test/unit'
require 'tablecon'

class Person
  def initialize name, age
    @name = name
    @age = age
  end
end

class TableconTest < Test::Unit::TestCase
	include Tablecon
	def setup
		@persons = [] 
		@persons << Person.new("Kurt", 30)
    @persons << Person.new("Scott", 40)
    @persons << Person.new("Eddie", 45)
  end

  def test_tabelable_exist
    table = Tablecon::Table.new @persons
  end

  def test_simple_table
    expected = '
+-------+-----+
| Name  | Age |
+-------+-----+
| Kurt  | 30  |
+-------+-----+
| Scott | 40  |
+-------+-----+
| Eddie | 45  |
+-------+-----+
'
    table = Tablecon::Table.new @persons
    puts "expected:"
    puts expected
    puts "actual:"
    puts table
    assert_equal expected.strip, table.to_s.strip
  end

  def test_columns
    list_parser = Tablecon::ListParser.new @persons
    cols = {}
    cols[:@name] = Tablecon::Column.new "Name", 5
    cols[:@age] = Tablecon::Column.new "Age", 3
    assert_equal cols,  list_parser.columns
  end
end
